home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 1 / Gold Medal Software Volume 1 (Gold Medal) (1994).iso / prog / tpwprog6.arj / BACKGRND.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-07-02  |  1.9 KB  |  87 lines

  1. { backgrnd.pas -- Use custom brush to paint window background }
  2.  
  3. program Backgrnd;
  4.  
  5. {$R brush.res}
  6.  
  7. uses WinTypes, WinProcs, WObjects;
  8.  
  9. const
  10.  
  11.   id_Pattern = 200;    { Resource ID of any 8-by-8 bitmap }
  12.  
  13. type
  14.  
  15.   BackgrndApplication = object(TApplication)
  16.     procedure InitMainWindow; virtual;
  17.   end;
  18.  
  19.   PBackgrndWindow = ^BackgrndWindow;
  20.   BackgrndWindow = object(TWindow)
  21.     Pattern: HBrush;  { Handle to brush made from bitmap }
  22.     constructor Init(AParent: PWindowsObject; ATitle: PChar);
  23.     destructor Done;
  24.       virtual;
  25.     function GetClassName: PChar;
  26.       virtual;
  27.     procedure GetWindowClass(var AWndClass: TWndClass);
  28.       virtual;
  29.   end;
  30.  
  31.  
  32. { BackgrndApplication }
  33.  
  34. {- Initialize BackgrndApplication object's window }
  35. procedure BackgrndApplication.InitMainWindow;
  36. begin
  37.   MainWindow := New(PBackgrndWindow, Init(nil, 'Backgrnd'))
  38. end;
  39.  
  40.  
  41. { BackgrndWindow }
  42.  
  43. {- Construct BackgrndWindow object }
  44. constructor BackgrndWindow.Init(AParent: PWindowsObject; ATitle: PChar);
  45. var
  46.   H: HBitmap;
  47. begin
  48.   TWindow.Init(AParent, ATitle);
  49.   H := LoadBitmap(HInstance, PChar(id_Pattern));
  50.   Pattern := CreatePatternBrush(H);
  51.   DeleteObject(H)
  52. end;
  53.  
  54. {- Destroy BackgrndWindow object and the custom brush }
  55. destructor BackgrndWindow.Done;
  56. begin
  57.   DeleteObject(Pattern);
  58.   TWindow.Done
  59. end;
  60.  
  61. function BackgrndWindow.GetClassName: PChar;
  62. begin
  63.   GetClassName := 'BkgWin'
  64. end;
  65.  
  66. procedure BackgrndWindow.GetWindowClass(var AWndClass: TWndClass);
  67. begin
  68.   TWindow.GetWindowClass(AWndClass);
  69.   AWndClass.hbrBackground := Pattern
  70. end;
  71.  
  72. var
  73.  
  74.   BackgrndApp: BackgrndApplication;
  75.  
  76. begin
  77.   BackgrndApp.Init('BackgrndApp');
  78.   BackgrndApp.Run;
  79.   BackgrndApp.Done
  80. end.
  81.  
  82.  
  83. {--------------------------------------------------------------
  84.   Copyright (c) 1991 by Tom Swan. All rights reserved.
  85.   Revision 1.00    Date: 2/26/1991
  86. ---------------------------------------------------------------}
  87.